<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
    width: 44%;
    display: inline-block;
    padding: 5px 3%;
    text-align: right;
  }

  .rj-cell span {
    font-size: 14px;
    color: #333;
    display: inline-block;
    width: 50%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-cells {
    margin-top: 0;
  }

  .weui-cells_form {
    background: #fbfbfb;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
  }

  .oitem {
    padding: 3px;
  }

  .hide {
    display: none;
  }

  #acts {
    font-size: 0;
  }

  #acts span {
    font-size: 14px;
  }

  .halfbtn {
    display: inline-block;
    width: 49%;
  }

  .weui-label {
    text-align: left;
  }

  .time {
    border: none;
    font-size: 17px;
  }

  .weui-cell_select {
    padding: 10px 15px;
  }

  .weui-select {
    height: auto;
    line-height: normal;
  }


  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }

  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }

  .weui_uploader_files {
    list-style: none;
  }

  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }

  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }

  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }

  .weui_uploader_bd {
    overflow: hidden;
  }

  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .outstore >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }

  .outstore >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }

  .weui-cell.fir {
    border-top: 0;
  }

  .help {
    text-align: right;
    padding: 5px;
    font-size: 12px;
    color: #bbb;
  }

  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }

  .addPur >>> .ui.selection.dropdown {
    border: none;
  }
  .addPur >>> .ui.dropdown .menu>.item {
    font-size: 18px;
  }
  .addPur >>> .ui.search.dropdown>.text {
    font-size: 18px;
  }

  /*.addPur >>> .ui.search.dropdown>.text {*/
  /*  line-height: 20px;*/
  /*}*/
</style>
<template>
  <div class="addPur" style="overflow: hidden;">
    <div
      style="height: 50px; line-height: 50px; background: #f7f7f7; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      录入采收合同
      <a href="javascript:" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <div class="weui-cells weui-cells_form">
      <form action="" method="post" id="formid">
        <input type="hidden" name="harvestType" :value="harvestType"/>
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">名称</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="name" ref="name">
            </div>
          </div>
<!--          <div class="weui-cell">-->
<!--            <div class="weui-cell__hd"><label class="weui-label">采收方式</label></div>-->
<!--            <div class="weui-cell__bd">-->
<!--              <select class="weui-select" name="type" v-model="htype">-->
<!--                <option value="">请选择</option>-->
<!--                <option v-for="dict in harvestMethods" :value="dict.dictValue" :key="dict.dictValue">{{ dict.dictLabel }}</option>-->
<!--              </select>-->
<!--            </div>-->
<!--          </div>-->
<!--          <div class="cellgroup">-->
<!--            <div class="weui-cell">-->
<!--              <div class="weui-cell__hd"><label class="weui-label">采收类型</label></div>-->
<!--              <div class="weui-cell__bd">-->
<!--                <select class="weui-select" name="harvestType" v-model="harvestType">-->
<!--                  <option value="">请选择</option>-->
<!--                  <option v-for="dict in harvestTypes" :value="dict.dictValue" :key="dict.dictValue">{{ dict.dictLabel }}</option>-->
<!--                </select>-->
<!--              </div>-->
<!--            </div>-->

<!--          </div>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">采收主体</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" class="weui-input" name="parta" :value="parta.name"/>
              <input type="hidden" name="orgId" :value="parta.id"/>
              <select class="weui-select" name="" v-model="parta">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in companys" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">部门</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="deptId" :value="depart.deptId"/>
              <input type="hidden" name="departname" :value="depart.deptName"/>
              <select class="weui-select" v-model="depart">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in departments" :key="item.deptId" :value="item">
                  {{ item.deptName }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">入库库房</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="srguid" :value="room.guid"/>
              <input type="hidden" name="srname" :value="room.name"/>
              <select class="weui-select" v-model="room">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in rooms" :key="item.guid" :value="item">
                  {{ item.name }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">质检标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="qamainid" v-model="qamain">
                <option value="">请选择</option>
                <option v-for="qamain in qamains" :value="qamain.guid" :key="qamain.guid">{{ qamain.qaname }}</option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">供应商</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="supplierId" :value="partb"/>
              <input type="hidden" name="supplierName" :value="plantor.name"/>
              <model-list-select :list="plantors"
                                 v-model="partb"
                                 option-value="id"
                                 option-text="name"
                                 placeholder="请选择">
              </model-list-select>
            </div>
          </div>
<!--          <div class="weui-cell" v-if="htype == 2">-->
<!--            <div class="weui-cell__hd"><label class="weui-label">农户库</label></div>-->
<!--            <div class="weui-cell__bd">-->
<!--              <input type="hidden" name="farmerstoreid" :value="farmerroom.guid"/>-->
<!--              <input type="hidden" name="farmerstore" :value="farmerroom.name"/>-->
<!--              <select class="weui-select" v-model="farmerroom">-->
<!--                <option value="" disabled>请选择</option>-->
<!--                <option v-for="(item, index) in farmerRooms" :key="item.guid" :value="item">-->
<!--                  {{ item.name }}-->
<!--                </option>-->
<!--              </select>-->
<!--            </div>-->
<!--          </div>-->
          <div class="weui-cell weui-cell_select" v-if="htype == 1">
            <div class="weui-cell__hd"><label class="weui-label">地块</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="arealandid" ref="arealandid">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in arealands" :key="item.guid" :value="item.guid">
                  {{ item.aname }}
                </option>
              </select>
            </div>
          </div>
        </div>
        <template v-if="partb">
        <div style="font-size: 0;margin: -6px 0;">
          <div class="weui-cells__title" style="display: inline-block; width: 35%;">付款信息</div>
          <div style="display: inline-block; width: 55%;text-align: right">
            <label for="weuiAgree" class="weui-agree">
              <input id="weuiAgree" type="checkbox" checked name="saveFlag" value="1" class="weui-agree__checkbox">
              <span class="weui-agree__text">
                保存付款信息
              </span>
            </label>
          </div>
        </div>
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">开户行</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="bank" v-model="plantor.bank"/>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">银行账号</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" name="bankcode" v-model="plantor.bankcode"/>
            </div>
          </div>
        </div>
      </template>
        <div class="weui-cells__title">产品信息</div>
        <div class="cellgroup">
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">产品</label></div>
            <div class="weui-cell__bd">
              <input type="hidden" name="productguid" :value="product.guid"/>
              <input type="hidden" name="productname" :value="product.productname"/>
              <select class="weui-select" v-model="product">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in products" :key="item.guid" :value="item">
                  {{ item.productname }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">规格</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="text" name="specificationname" ref="specification"/>
            </div>
          </div>
          <div class="weui-cell" v-if="harvestType == 2">
            <div class="weui-cell__hd"><label class="weui-label">采收数量</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input inlinput1" type="text" name="weight" v-model="weight" placeholder="请输入" required />
              <input class="weui-input inlinput2" type="text" readonly value="吨" />
            </div>
          </div>
          <input type="hidden" name="qatype" value="1">
          <!--            <div class="weui-cell">-->
          <!--              <div class="weui-cell__hd"><label class="weui-label">质检方式</label></div>-->
          <!--              <div class="weui-cell__bd">-->
          <!--                <select class="weui-select" name="qatype" ref="qatype">-->
          <!--                  <option value="1" selected>库房质检</option>-->
          <!--&lt;!&ndash;                  <option value="2">地头质检</option>&ndash;&gt;-->
          <!--                </select>-->
          <!--              </div>-->
          <!--            </div>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">支付方式</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="paymentmethod" v-model="paymentmethod">
<!--                <option value="1" :disabled="currQamainType == 2">装车付</option>-->
<!--                <option value="2">验收付</option>-->
                <option v-for="dict in harvestPaytypes" :value="dict.dictValue" :key="dict.dictValue">{{ dict.dictLabel }}</option>
              </select>
            </div>
          </div>
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">扣杂方式</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="deducttype" v-model="deducttype">
                <option value="" disabled>请选择</option>
                <option v-for="(item, index) in deducttypes" :key="item.createTime" :disabled="packDeduct(item.dictValue)"
                        :value="item.dictValue">
                  {{ item.dictLabel }}
                </option>
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 1">
            <div class="weui-cell__hd"><label class="weui-label">扣杂标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="isdiscount" v-model="isdiscount">
                <option v-for="(item, index) in isdiscounts"
                        v-if="item.dictValue == 1 || item.dictValue == 2 ||  item.dictValue == 3"
                        :disabled="packIsdist(item.dictValue)" :value="item.dictValue">
                  {{ item.dictLabel }}
                </option>
                <!--                  <option value="">请选择</option>-->
                <!--                  <option value="1"> 按照合同约定的扣杂率扣杂</option>-->
                <!--                  <option value="2" :disabled="paymentmethod == 1">按照质检结果扣杂</option>-->
                <!--                  <option value="3" :disabled="paymentmethod == 1"> 合同和质检结果取最大扣杂</option>-->
                <!-- lrj-0831 将选项4放到分步扣杂下-->
                <!--                  <option value="4" :disabled="paymentmethod == 1">按质检结果分级扣杂</option>-->
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 2">
            <div class="weui-cell__hd"><label class="weui-label">扣杂标准</label></div>
            <div class="weui-cell__bd">
              <select class="weui-select" name="isdiscount" v-model="isdiscount">
                <option v-for="(item, index) in isdiscounts" v-if="item.dictValue == 5 ||  item.dictValue == 6"
                        :disabled="packIsdist(item.dictValue)" :value="item.dictValue">
                  {{ item.dictLabel }}
                </option>
                <!--                  <option value="">请选择</option>-->
                <!--                  <option value="4" :disabled="paymentmethod == 1">按质检结果分级扣杂</option>-->
                <!--                  <option value="6" :disabled="paymentmethod == 1">优质优价</option>-->
              </select>
            </div>
          </div>
          <div class="weui-cell" v-if="deducttype == 1">
            <div class="weui-cell__hd"><label class="weui-label">扣杂率(%)</label></div>
            <div class="weui-cell__bd">
              <input class="weui-input" type="number" name="discountrate" ref="discountrate">
            </div>
          </div>
          <input type="hidden" name="setlwgtype" value="2"/>
<!--          <div class="weui-cell" v-if="isdiscount == 6">-->
<!--            <div class="weui-cell__hd"><label class="weui-label">区域</label></div>-->
<!--            <div class="weui-cell__bd">-->
<!--              <input type="hidden" name="region" :value="region.dictkey"/>-->
<!--              <input type="hidden" name="regionName" :value="region.dicttext"/>-->
<!--              <select class="weui-select" v-model="region">-->
<!--                <option value="" disabled>请选择</option>-->
<!--                <option v-for="(item, index) in regions" :key="item.dictkey" :value="item">-->
<!--                  {{ item.dicttext }}-->
<!--                </option>-->
<!--              </select>-->
<!--            </div>-->
<!--          </div>-->
<!--          <input type="hidden" name="region" value="" v-if="isdiscount != 6"/>-->
<!--          <input type="hidden" name="regionName" value="" v-if="isdiscount != 6"/>-->
<!--          <div class="weui-cell" v-if="isdiscount == 6">-->
<!--            <div class="weui-cell__hd"><label class="weui-label">系列</label></div>-->
<!--            <div class="weui-cell__bd">-->
<!--              <input type="hidden" name="series" :value="serie.dictkey"/>-->
<!--              <input type="hidden" name="seriesName" :value="serie.dicttext"/>-->
<!--              <select class="weui-select" v-model="serie">-->
<!--                <option value="" disabled>请选择</option>-->
<!--                <option v-for="(item, index) in series" :key="item.dictkey" :value="item">-->
<!--                  {{ item.dicttext }}-->
<!--                </option>-->
<!--              </select>-->
<!--            </div>-->
<!--          </div>-->
<!--          <input type="hidden" name="series" value="1" v-if="isdiscount != 6"/>-->
<!--          <input type="hidden" name="seriesName" value="" v-if="isdiscount != 6"/>-->
          <div class="weui-cell">
            <div class="weui-cell__hd"><label class="weui-label">单价</label></div>
            <div class="weui-cell__bd">
<!--              <template v-if="currQamainType == 2">-->
<!--                <input class="weui-input inlinput0" type="number" name="price" ref="price">-->
<!--                <input class="weui-input  inlinput3" type="text" value="元/淀粉含量*吨">-->
<!--                <p v-if="price == ''" style="font-size: 12px;text-align: right;margin-right: 10px;margin-left: 15px;color: red;">没有获取到淀粉薯采收单价</p>-->
<!--              </template>-->
<!--              <template v-else>-->
                <input class="weui-input inlinput0" type="number" name="price" ref="price">
                <input class="weui-input inlinput3" type="text" value="元/吨">
<!--              </template>-->
            </div>
          </div>
        </div>
<!--        <div v-if="isdiscount == 5 || isdiscount == 6">-->
<!--          <div class="oitem" v-for="(currStandard, itemNo) in packIsval(standards)">-->
<!--            <template v-if="currStandard.isvaluation == 1">-->
<!--              <div class="weui-cells__title">扣杂分级标准{{ itemNo + 1 }}</div>-->
<!--              <div class="weui-cell weui-cell_select fir">-->
<!--                <div class="weui-cell__hd"><label class="weui-label">分级标准</label></div>-->
<!--                <div class="weui-cell__bd">-->
<!--                  <input type="hidden" :name="'standars[' + itemNo + '].standard'" :value="currStandard.standard">-->
<!--                  <input type="hidden" :name="'standars[' + itemNo + '].standardid'" :value="currStandard.guid">-->
<!--                  <select class="weui-select standard">-->
<!--                    <option :value="currStandard" selected>{{ currStandard.standard }}</option>-->
<!--                  </select>-->
<!--                </div>-->
<!--              </div>-->
<!--              <div class="weui-cell">-->
<!--                <div class="weui-cell__hd"><label class="weui-label">单价</label></div>-->
<!--                <div class="weui-cell__bd">-->
<!--                  <input class="weui-input inlinput1 price" type="number" :name="'standars[' + itemNo + '].price'"-->
<!--                         placeholder="请输入单价">-->
<!--                  <input class="weui-input inlinput2" type="text" value="元/吨">-->
<!--                </div>-->
<!--              </div>-->
<!--            </template>-->
<!--          </div>-->
<!--        </div>-->
        <div class="weui-btn-area">
          <a class="weui-btn weui-btn_primary subbtn" href="javascript:" @click="postForm()">提交</a>
        </div>
      </form>
    </div>
  </div>
</template>

<script>
  import 'vue-search-select/dist/VueSearchSelect.css'
  import { ModelListSelect } from 'vue-search-select'
  import UploadFile3 from "@/components/common/UploadFile3";
  import qs from 'qs';

  export default {
    name: 'AddProCtract2',
    data() {
      return {
        batches: [],
        bitchid: '',
        plantors: [],
        partb: '',
        bankcode: '',
        bank: '',
        arealands: [],
        arealandid: '',
        products: [],
        product: '',
        specs: [],
        specification: '',
        deducttypes: [],
        deducttype: 1,
        isdiscounts: [],
        isdiscount: '',
        parta: '',
        companys: [],
        rooms: [],
        room: '',
        farmerRooms: [],
        farmerroom: '',
        departments: [],
        depart: '',
        setlwgtype: 1,
        paymentmethod: 2,
        batch: '',
        standards: '',
        oitems: [0],
        qamains: '',
        qamain: '',
        htype: 1,
        supplyers: [],
        supplyerid: '',
        supplyer: '',
        series: [],
        serie: '',
        regions: [],
        region: '',
        weight: '',
        harvestType: 2,
        artoken: '',
        currQamainType: '',
        price: '',
        harvestMethods: [],
        harvestTypes: [],
        harvestPaytypes: [],
        plantor: ''
      }
    },
    components: {ModelListSelect, UploadFile3},
    async mounted() {
      this.getDepartment();
      this.getOrgs();
      this.getPlantors();
      this.getQamains();
      this.getDeductypes();
      this.getIsdiscounts();
      this.getHarvestMethods();
      // this.getHarvestTypes();
      this.getHarvestPaytypes();
      this.getProducttypes();
      this.getProducts();
    },
    watch: {
      parta: function (val) {
        this.getRooms(val.guid);
        // this.getPrice(val.guid);
      },
      partb: function (val) {
        this.plantor = this.plantors.find(item => item.id == val);
          this.arealands = [];
        // if (this.htype == 1) {

        this.plantor.userid && this.getArealands(this.plantor.userid);
        // } else if (this.htype == 2) {
        //   this.getFamerRooms();
        // }
        // this.getSupplier(val);
      },
      paymentmethod: function (val) {
        if (val == 1) {
          this.isdiscount = 1;
          this.deducttype = 1;
        }
      },
      deducttype: function (val) {
        if (val == 2) {
          this.isdiscount = 5;
        } else if (val == 1) {
          this.isdiscount = 1;
        }
      },
      isdiscount: function (val) {
        if (val == 5 || val == 6) {
          if (this.standards == '') {
            this.getStandards();
          }
        }
      },
      // htype: function (val) {
      //   if (val == 2) {
      //     this.getFamerRooms();
      //   }
      // },
      product: function (val) {
        this.serie = this.series.filter(item => {
          return item.dictkey == val.series;
        })[0] || '';
      },
      qamain: function (val) {
        let currQamain = this.qamains.find(item => item.guid == val);
        if (!currQamain) return;
        this.currQamainType = currQamain.type;
        if (this.currQamainType == 2) {
          this.deducttype = 1;
          // this.isdiscount = 2;
          this.paymentmethod = 2;
          this.getPrice(this.parta.guid);
        }
      },
    },
    methods: {
      packDeduct: function (deduct) {
        let res = false;
        switch (deduct) {
          case 2:
            res =  (this.currQamainType == 2 || this.paymentmethod == 1) ? true : false;
            break;
        }
        return res;
      },
      packIsdist: function (isdis) {
        let res = false;
        switch (parseInt(isdis)) {
          case 2:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 3:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 4:
            res = this.paymentmethod == 1 ? true : false;
            break;
          case 6:
            res = this.paymentmethod == 1 ? true : false;
            break;
        }
        return res;
      },
      packIsval: function (standers) {
        if (standers.length == 0) {
          return [];
        }
        return standers.filter(item => {
          return item.isvaluation == 1;
        });
      },
      getProducts: function () {
        this.axios({
          method: 'get',
          responseType: 'json',
          url: '/prod-api/getProducts',
          params: {productflag: 1}
        }).then(response => {
          if (response.data.code == 200) {
            this.products = response.data.data;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastText('获取货品数据失败')
          }
        });
      },
      getSpecs: function() {
        if (!this.product) {
          return;
        }
        this.axios({
          method: 'get',
          url: '/prod-api/getSpecs',
          params: {productGuid: this.product.guid}
        }).then((response) => {
          if (response.data.code == 200) {
            this.specs = response.data.data;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError("获取规格数据失败");
          }
        })
      },
      getQamains: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/quality/qamain/findQamainList',
          params: {status: 0}
        }).then(response => {
          if (response.data.code == 200) {
            that.qamains = response.data.data;
          } else {
            this.toastText('获取质检标准数据失败');
          }
        });
      },
      getDeductypes: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/procurementcontract_deducttype',
        }).then(response => {
          if (response.data.code == 200) {
            that.deducttypes = response.data.data;
          } else {
            this.toastText('获取扣杂方式数据失败');
          }
        });
      },
      getStandards: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/product_type',
        }).then(response => {
          if (response.data.code == 200) {
            that.standards = response.data.data;
          } else {
            this.toastText('获取扣杂方式数据失败');
          }
        });
      },
      getIsdiscounts: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/procurementcontract_isdiscount',
        }).then(response => {
          if (response.data.code == 200) {
            that.isdiscounts = response.data.data;
          } else {
            this.toastText('获取扣杂标准数据失败');
          }
        });
      },
      getHarvestMethods: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/harvest_method',
        }).then(response => {
          if (response.data.code == 200) {
            that.harvestMethods = response.data.data;
          } else {
            this.toastText('获取采收方式数据失败');
          }
        });
      },
      getHarvestTypes: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/harvest_type',
        }).then(response => {
          if (response.data.code == 200) {
            that.harvestTypes = response.data.data;
          } else {
            this.toastText('获取采收类型数据失败');
          }
        });
      },
      getHarvestPaytypes: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/harvest_paytype',
        }).then(response => {
          if (response.data.code == 200) {
            that.harvestPaytypes = response.data.data;
          } else {
            this.toastText('获取采收支付方式数据失败');
          }
        });
      },
      getProducttypes: async function() {
        let that = this;
        await this.axios({
          method: 'get',
          url: '/prod-api/system/dict/data/type/product_type',
        }).then(response => {
          if (response.data.code == 200) {
            that.productTypes = response.data.data.filter(item => [2, 4].includes(parseInt(item.dictValue)));
          } else {
            this.toastText('获取货品类型数据失败');
          }
        });
      },
      getRooms: function(orgId) {
        this.axios({
          method: 'get',
          url: '/prod-api/getStoreRoomByOrgIdOrPermissions',
          params: {guid: orgId, enable: 1}
        }).then(response => {
          if (response.data.code == 200) {
            this.rooms = response.data.data;
          } else {
            this.toastText('获取库房数据失败');
          }
        });
      },
      getArealands: function(plantorid) {
        this.axios({
          method: 'get',
          url: '/prod-api/tarealand/arealand/getAreaLandsByFarmerId',
          params: {farmerid: plantorid}
        }).then(response => {
          if (response.data.code == 200) {
            this.arealands = response.data.data;
          } else {
            this.toastText('获取地块数据失败')
          }
        });
      },
      getFamerRooms: function() {
        this.axios({
          method: 'get',
          url: '/prod-api/store/storeroom/getStoreroom',
          params: {orgguids: this.partb}
        }).then(response => {
          if (response.data.code == 200) {
            this.farmerRooms = response.data.data;
          } else {
            this.toastText('获取库房数据失败')
          }
        });
      },
      getSupplier: function(userid) {
        this.axios({
          method: 'get',
          url: '/prod-api/organization/supplier/findSupploerlist',
          params: {userid: userid}
        }).then(response => {
          if (response.data.code == 200) {
            this.supplyer = response.data.data[0] || {};
            this.bankcode = this.supplyer.bankcode;
            this.bank = this.supplyer.bank;
          } else {
            this.toastText('获取供应商数据失败')
          }
        });
      },
      getPrice: function() {
        // this.axios({
        //   method: 'get',
        //   url: '/prod-api/getSuppliers',
        //   // params: {types: this.suppliertype}
        // }).then(response => {
        //   if (response.data.code == 200) {
        //     this.suppliers = response.data.data;
        //   } else {
        //     this.toastText('获取供应商数据失败')
        //   }
        // });
      },
      getOrgs: function() {
        this.axios({
          method: 'get',
          url: '/prod-api/getOrgs',
        }).then(response => {
          if (response.data.code == 200) {
            this.companys = response.data.data;
          } else {
            this.toastText('获取主体数据失败')
          }
        });
      },
      getDepartment: function () {
        let that = this;
        this.axios({
          method: 'get',
          url: '/prod-api/getDepsByPermissionCode',
          params: {code: 38}
        }).then(response => {
          if (response.data.code == 200) {
            that.departments = response.data.data;
            this.depart = response.data.data[0] || '';
          }  else {
            this.toastText('获取部门数据失败');
          }
        });
      },
      getPlantors: function () {
        // this.axios({
        //   method: 'get',
        //   url: '/prod-api/system/user/list',
        //   params: {userType: 1}
        // }).then(response => {
        //   if (response.data.code == 200) {
        //     this.plantors = response.data.rows;
        //   }  else {
        //     this.toastText('获取种植户数据失败');
        //   }
        // });
        this.axios({
          method: 'get',
          url: '/prod-api/organization/supplier/findSupploerlist',
          params: {type: 1}
        }).then(response => {
          if (response.data.code == 200) {
            this.plantors = response.data.data;
          } else {
            this.toastText('获取供应商数据失败')
          }
        });
      },
      //提交表单数据
      postForm: function () {
        let that = this;
        //表单校验
        if (!this.checkFormElm()) {
          return false;
        }
        if (!this.partb) {
          $.confirm('确定要创建无供应商合同？', function () {
            //防止重复提交
            $('.subbtn').attr("disabled",true).css("pointer-events","none");
            //显示提交状态
            $.showLoading("正在提交");
            let postData = that.serialize2Obj($("#formid").serializeArray());
            // postData.fileIds = this.fileids.join(',');
            // postData = JSON.parse(postData)
            that.axios({
              method: 'post',
              url: `/prod-api/harvest/procurementcontract/save`,
              data: postData
            }).then(response => {
              //恢复提交按钮可点击
              $('.subbtn').attr('disabled', false).css("pointer-events","auto");
              //关闭提交状态
              $.hideLoading();

              if (response.data.code == 200) {
                that.toastSuccess("保存成功");
                that.$router.push({name: 'ProCtractList2'});
              } else {
                that.toastError('系统错误');
              }
            }).catch(function (error) {
              //恢复提交按钮可点击
              $('.subbtn').attr('disabled', false).css("pointer-events","auto");
              //关闭提交状态
              $.hideLoading();
              that.toastError('系统错误');
            });
          })
        } else {
          //防止重复提交
          $('.subbtn').attr("disabled",true).css("pointer-events","none");
          //显示提交状态
          $.showLoading("正在提交");
          let postData = this.serialize2Obj($("#formid").serializeArray());
          // postData.fileIds = this.fileids.join(',');
          // postData = JSON.parse(postData)
          this.axios({
            method: 'post',
            url: `/prod-api/harvest/procurementcontract/save`,
            data: postData
          }).then(response => {
            //恢复提交按钮可点击
            $('.subbtn').attr('disabled', false).css("pointer-events","auto");
            //关闭提交状态
            $.hideLoading();

            if (response.data.code == 200) {
              this.toastSuccess("保存成功");
              this.$router.push({name: 'ProCtractList2'});
            } else if (response.data.msg) {
              this.toastText(response.data.msg);
            } else {
              this.toastError('系统错误');
            }
          }).catch(function (error) {
            //恢复提交按钮可点击
            $('.subbtn').attr('disabled', false).css("pointer-events","auto");
            //关闭提交状态
            $.hideLoading();
            that.toastError('系统错误');
          });
        }
      },
      checkFormElm: function () {
        if (this.$refs.name && this.$refs.name.value == '') {
          this.toastText('请输入名称');
          return false;
        }
        // if (this.harvestType == '') {
        //   this.toastText('请选择采收类型');
        //   return false;
        // }
        if (this.harvestType == 2 && (this.weight == '' || this.weight <= 0)) {
          this.toastText('采收数量有误');
          return false;
        }
        if (this.parta == '' || this.parta == undefined) {
          this.toastText('请选择采收主体');
          return false;
        }
        if (this.depart == '' || this.depart == undefined) {
          this.toastText('请选择部门');
          return false;
        }
        // if (this.partb == '') {
        //   this.toastText('请选择供应商');
        //   return false;
        // }
        // if (this.partb && this.htype == 2 && this.farmerroom == '') {
        //   this.toastText('请选择农户库');
        //   return false;
        // }
        // if (this.partb && this.currQamainType == 1 && this.$refs.arealandid && this.$refs.arealandid.value == '') {
        //   this.toastText('请选择地块');
        //   return false;
        // }
        if (this.partb && this.plantor && !this.plantor.bankcode) {
          this.toastText('请录入银行账号');
          return false;
        }
        if (this.partb && this.plantor && !this.plantor.bank) {
          this.toastText('请录入开户行');
          return false;
        }
        if (this.partb && !this.product) {
          this.toastText('请选择产品');
          return false;
        }
        if (this.$refs.specification && this.$refs.specification.value == '') {
          this.toastText('请输入规格');
          return false;
        }
        // if (this.isdiscount == 6 && !this.region) {
        //   this.toastText('请选择区域');
        //   return false;
        // }
        // if (this.isdiscount == 6 && !this.serie) {
        //   this.toastText('请选择产品系列');
        //   return false;
        // }
        // if (this.currQamainType == 2 && (this.price == '' || this.price == undefined)) {
        //   this.toastText('单价不能为空');
        //   return false;
        // }
        if (this.$refs.price && this.$refs.price.value == '') {
          this.toastText('请输入单价');
          return false;
        }
        // if (this.currQamainType == 2 && this.$refs.price && this.$refs.price.value != '' && parseFloat(this.$refs.price.value) > 100) {
        //   this.toastText('请纠正您输入的单价，淀粉含量单价高于常规');
        //   return false;
        // }
        if (!this.qamain) {
          this.toastText('请选择质检标准');
          return false;
        }
        // if (this.$refs.qatype && this.$refs.qatype.value == '') {
        //   this.toastText('请选择质检方式');
        //   return false;
        // }
        if (this.isdiscount == '') {
          this.toastText('请选择扣杂标准');
          return false;
        }
        if (this.deducttype == 1 && this.$refs.discountrate && this.$refs.discountrate.value == '') {
          this.toastText('请输入扣杂率');
          return false;
        }
        if (this.room == '') {
          this.toastText('请选择入库库房');
          return false;
        }
        if (!this.checkEmy('standard')) {
          $.alert('明细分级标准不能为空！');
          return false;
        }
        // if (!this.checkEmy2('price')) {
        //   $.alert('明细单价不能为空！');
        //   return false;
        // }
        return true;
      }
    }
  }
</script>
